# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
from 树.二叉树.BuildTree import *


class Solution:
    def sumNumbers(self, root: Optional[TreeNode]) -> int:
        self.ans = 0

        def dfs(node: TreeNode, acc):
            ne = acc * 10 + node.val
            if not node.left and not node.right:
                self.ans += ne
                return
            if node.left:
                dfs(node.left, ne)
            if node.right:
                dfs(node.right, ne)

        dfs(root, 0)
        return self.ans


if __name__ == '__main__':
    s = Solution()

    null = None
    root = build_tree_from_level_order([1, 2, 3])
    r = s.sumNumbers(root)
    print(r)
